package com.jiayu.seckilldemo.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：jiayu
 * @description：消息发送者
 * @date ：2022/7/28 11:00
 */
@Service
@Slf4j
public class MQSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;
//
//    /**
//     *发送秒杀信息
//     * @param message
//     */
    public void sendSeckillMessage(Object message) {
        log.info("发送消息" + message);
//        rabbitTemplate.convertAndSend("seckillExchange", "seckill.message", message);
        rabbitTemplate.convertAndSend("seckillExchange","seckill.msg",message);
    }

//    fanoutExchange 交换机 fanout模式
    public void send01(Object message) {
        log.info("发送消息" + message);
        rabbitTemplate.convertAndSend("fanoutExchange","",message);
    }

    //   DirectExchange 交换机 direct模式
    public void send02(Object message) {
        log.info("发送red消息" + message);
        rabbitTemplate.convertAndSend("directExchange","queue.red",message);
    }
    public void send03(Object message) {
        log.info("发送green消息" + message);
        rabbitTemplate.convertAndSend("directExchange","queue.green",message);
    }
    public void send04(Object message) {
        log.info("发送red消息" + message);
        rabbitTemplate.convertAndSend("topicExchange","queue.red.message",message);
    }
    public void send05(Object message) {
        log.info("发送green消息" + message);
        rabbitTemplate.convertAndSend("topicExchange","queue.green.message",message);
    }



}
